package com.demo.my.Controller;

import com.demo.my.Entity.Position;
import com.demo.my.Service.PositionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addPosition")
public class AddPositionServlet extends HttpServlet {
    private PositionService positionService=new PositionService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            Integer positionNumber = Integer.parseInt(req.getParameter("positionNumber"));
            String name = req.getParameter("name");
            String level = req.getParameter("level");
            String notes = req.getParameter("notes");
            Position position = new Position(0,positionNumber, name, level, notes);
            positionService.addPosition(position);
            req.getRequestDispatcher("positionList").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
